from flask import Flask, render_template, redirect
from flask import request

app = Flask(__name__)


# @app.route('/')
# def index():
#     user_agent = request.headers
#     return '<p>Your browser is %s<p>' % user_agent
@app.route('/')
def hello_world():
    return redirect('/clearmac')


@app.route('/abc/<name>')
def helloabc(name):
    return '<h1>hello %s</h1>' % name


@app.route('/intger/<int:id>')
def helloint(id):
    return 'hello %s' % id


'''@app.route('/')
def index():
    return "welcome to wolan_ali devops system!"'''


@app.route('/clearmac', methods=['POST', 'GET'])
def login():
    error = None
    if request.method == 'POST':
        if request.form.get('passwd') == 'zjb1990':
            # return '{} '.format(request.form.get('fname'))
            phonenum = request.form.get('fname')
            s.os.chdir('/root/shell')
            s.os.system('bash /root/shell/clearphone.sh {}'.format(phonenum))
            error = '{}解绑成功'.format(phonenum)
            return render_template('index.html', error=error)
        else:
            error = '执行密码错误'
            return render_template('index.html', error=error)
    return render_template('index.html', error=error)
    # if request.form['username'] == 'abc' and request.form['password'] == '123':
    #     return request.form['username']
    # else:
    #    error = 'Invalid username/password'


if __name__ == '__main__':
    app.run()
